package com.jcnet.bizaia;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings.SettingNotFoundException;
import android.widget.ImageView;
import cn.sharesdk.framework.ShareSDK;

import com.jcnet.bizaia.bean.SPSetting;
import com.jcnet.bizaia.bean.SPUserBean;
import com.jcnet.bizaia.tools.DataStorageHelper;
import com.jcnet.bizaia.tools.JCTools;
public class WelcomeActivity extends Activity {


	private DataStorageHelper SettingDataStorageHelper ;
	
	private DataStorageHelper userDataStorageHelper;
	
	private ImageView imageView;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ShareSDK.initSDK(this,"androidv1101");
		setContentView(R.layout.welcome);
		imageView = (ImageView)findViewById(R.id.welcomeImg);
		
		
		SettingDataStorageHelper = new DataStorageHelper(this, SPSetting.SETTING_TABLE_NAME);
		userDataStorageHelper = new DataStorageHelper(this, SPUserBean.dataTableNameForUser);
		
		initAnim();
		
	}
	
	
	private void initAnim() {
		// TODO Auto-generated method stub
		
		com.nineoldandroids.animation.ObjectAnimator animator = 
				com.nineoldandroids.animation.ObjectAnimator.ofFloat(imageView,"alpha", 0f, 1f);
		animator.setDuration(3000);
        
        new Handler().postDelayed(new Runnable() {  
            public void run() {  
				
				//第一次进入选择城市
				if((SettingDataStorageHelper.getInt(SPSetting.CHOOSE_COUNTRY_ID, -100)==-100)
						&&(SettingDataStorageHelper.getInt(SPSetting.CHOOSE_PREFECTURE_ID, -100)==-100)
							){
						//默认城市ID 都不为空的时候   说明第一次进入
						startActivity(new Intent(WelcomeActivity.this, FirstInAdressActivity.class));
						finish();
						return;
					}
				//第一次登录没有登录账户
				if(JCTools.isLogin(WelcomeActivity.this)==false){  //判断是否登录
					
					Intent intent = new Intent(WelcomeActivity.this, LoginActivity.class);
					intent.putExtra("firstIn", 100);
					startActivity(intent);
					
				}else{
					Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
					//firstIn
					intent.putExtra("firstIn", 100);
					startActivity(intent);
				}
				
				finish();
            }  
        }, 3000);  
		
	}
}
